home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOR (English Version)
/
DOR (English Version).iso
/
directx.cab
/
dxdiacht.chm
/
langref.js
< prev
next >
Wrap
Text File
|
1999-09-09
|
19KB
|
794 lines
//
// Common code
//
var ie4 = false;
var advanced = false;
var curLang = null;
var showAll = true;
var cook = null;
var baseUrl = document.scripts[document.scripts.length - 1].src.replace(/[^\/]+.js/, "");
if (navigator.appName == "Microsoft Internet Explorer") {
var ver = navigator.appVersion;
var v = new Number(ver.substring(0,ver.indexOf(".", 0)));
if (v >= 4) {
advanced = true;
ie4 = true;
// Look for 5.x buried somewhere in the version string.
var toks = ver.split(/[^0-9.]/);
if (toks) {
for (var i = 0; i < toks.length; i++) {
var tok = toks[i];
if (tok.indexOf(".", 0) > 0) {
if (tok >= 5)
ie4 = false;
}
}
}
}
}
if (advanced)
window.onload = bodyOnLoad;
function bodyOnClick()
{
if (advanced) {
hideTip();
closeMenu();
hideSeeAlso();
}
}
function bodyOnLoad()
{
if (advanced) {
initLangs();
initReftips();
initSeeAlso();
document.body.onclick = bodyOnClick;
}
}
//
// Language filtering
//
function initLangs()
{
var hdr = document.all.hdr;
if (!hdr)
return;
var langs = new Array;
var spans = document.all.tags("SPAN");
if (spans) {
var iElem = spans.length;
for (iElem = 0; iElem < spans.length; iElem++) {
var elem = spans[iElem];
if (elem.className == "lang") {
// Update the array of unique language names.
var a = elem.innerText.split(",");
for (var iTok = 0; iTok < a.length; iTok++) {
var m = a[iTok].match(/([A-Za-z].*[A-Za-z+])/);
if (m) {
var iLang = 0;
while (iLang < langs.length && langs[iLang] < m[1])
iLang++;
if (iLang == langs.length || langs[iLang] != m[1]) {
var before = langs.slice(0,iLang);
var after = langs.slice(iLang);
langs = before.concat(m[1]).concat(after);
}
}
}
}
}
}
if (langs.length > 0) {
var pres = document.all.tags("PRE");
if (pres) {
for (var iPre = 0; iPre < pres.length; iPre++)
initPreElem(pres[iPre]);
}
var obj = document.all.obj_cook;
if (obj && obj.object) {
cook = obj;
var lang = obj.getValue("lang");
var iLang = langs.length - 1;
while (iLang && langs[iLang] != lang)
iLang--;
curLang = langs[iLang];
if (obj.getValue("lang.all") != "1")
showAll = false;
}
var iLim = document.body.children.length;
var head = null;
for (var i = 0; i < iLim; i++) {
var elem = document.body.children[i];
if (elem.tagName.match(/^(P)|(PRE)|([DOU]L)$/))
break;
if (elem.tagName.match(/^H[1-6]$/)) {
head = elem;
head.insertAdjacentHTML('BeforeEnd', '<SPAN CLASS=ilang></SPAN>');
}
}
var td = hdr.insertCell(0);
if (td) {
// Localizable strings.
var L_Filter_Tip = "Language Filtering"; // tooltip for language button
var L_Language = "Language"; // heading for menu of programming languages
var L_Show_All = "Show All"; // label for 'show all languages' menu item
// Add the language button to the button bar.
td.className = "button1";
td.style.width = "19px";
td.onclick = langMenu;
td.innerHTML = '<IMG SRC="' + baseUrl + 'Filter.gif' + '" ALT="' +
L_Filter_Tip + '" BORDER=0>';
// Add the menu.
var div = '<DIV ID="lang_menu" CLASS=langMenu><B>' + L_Language + '</B><UL>';
for (var i = 0; i < langs.length; i++)
div += '<LI><A HREF="" ONCLICK="chooseLang(this)">' + langs[i] + '</A><BR>';
div += '<LI><A HREF="" ONCLICK="chooseAll()">' + L_Show_All + '</A></UL></DIV>';
document.body.insertAdjacentHTML('BeforeEnd', div);
}
if (!showAll)
filterLang();
}
}
function initPreElem(pre)
{
var htm0 = pre.outerHTML;
var reLang = /<span\b[^>]*class="?lang"?[^>]*>/i;
var iFirst = -1;
var iSecond = -1;
iFirst = htm0.search(reLang);
if (iFirst >= 0) {
iPos = iFirst + 17;
iMatch = htm0.substr(iPos).search(reLang);
if (iMatch >= 0)
iSecond = iPos + iMatch;
}
if (iSecond < 0) {
var htm1 = trimPreElem(htm0);
if (htm1 != htm0) {
pre.insertAdjacentHTML('AfterEnd', htm1);
pre.outerHTML = "";
}
}
else {
var rePairs = /<(\w+)\b[^>]*><\/\1>/gi;
var substr1 = htm0.substring(0,iSecond);
var tags1 = substr1.replace(/>[^<>]+(<|$)/g, ">$1");
var open1 = tags1.replace(rePairs, "");
open1 = open1.replace(rePairs, "");
var substr2 = htm0.substring(iSecond);
var tags2 = substr2.replace(/>[^<>]+</g, "><");
var open2 = tags2.replace(rePairs, "");
open2 = open2.replace(rePairs, "");
pre.insertAdjacentHTML('AfterEnd', open1 + substr2);
pre.insertAdjacentHTML('AfterEnd', trimPreElem(substr1 + open2));
pre.outerHTML = "";
}
}
function trimPreElem(htm)
{
return htm.replace(/[ \r\n]*((<\/[BI]>)*)[ \r\n]*<\/PRE>/g, "$1</PRE>").replace(
/\w*<\/SPAN>\w*((<[BI]>)*)\w*\r\n/g, "\r\n</SPAN>$1"
);
}
function getBlock(elem)
{
while (elem && elem.tagName.match(/^[BIUA]|(SPAN)|(CODE)|(TD)$/))
elem = elem.parentElement;
return elem;
}
function langMenu()
{
bodyOnClick();
window.event.returnValue = false;
window.event.cancelBubble = true;
var div = document.all.lang_menu;
var lnk = window.event.srcElement;
if (div && lnk) {
var x = lnk.offsetLeft + lnk.offsetWidth - div.offsetWidth;
div.style.pixelLeft = (x < 0) ? 0 : x;
div.style.pixelTop = lnk.offsetTop + lnk.offsetHeight;
div.style.visibility = "visible";
}
}
function chooseLang(item)
{
window.event.returnValue = false;
window.event.cancelBubble = true;
if (item) {
closeMenu();
curLang = item.innerText;
showAll = false;
}
if (cook) {
cook.putValue('lang', curLang);
cook.putValue('lang.all', '');
}
filterLang();
}
function chooseAll()
{
window.event.returnValue = false;
window.event.cancelBubble = true;
closeMenu();
showAll = true;
if (cook)
cook.putValue('lang.all', '1');
unfilterLang();
}
function closeMenu()
{
var div = document.all.lang_menu;
if (div && div.style.visibility != "hidden") {
var lnk = document.activeElement;
if (lnk && lnk.tagName == "A")
lnk.blur();
div.style.visibility = "hidden";
}
}
function getNext(elem)
{
for (var i = elem.sourceIndex + 1; i < document.all.length; i++) {
var next = document.all[i];
if (!elem.contains(next))
return next;
}
return null;
}
function filterMatch(text, name)
{
var a = text.split(",");
for (var iTok = 0; iTok < a.length; iTok++) {
var m = a[iTok].match(/([A-Za-z].*[A-Za-z+])/);
if (m && m[1] == name)
return true;
}
return false;
}
function topicHeading(head)
{
var iLim = document.body.children.length;
var idxLim = head.sourceIndex;
for (var i = 0; i < iLim; i++) {
var elem = document.body.children[i];
if (elem.sourceIndex < idxLim) {
if (elem.tagName.match(/^(P)|(PRE)|([DOU]L)$/))
return false;
}
else
break;
}
return true;
}
function filterLang()
{
var spans = document.all.tags("SPAN");
for (var i = 0; i < spans.length; i++) {
var elem = spans[i];
if (elem.className == "lang") {
var newVal = filterMatch(elem.innerText, curLang) ? "block" : "none";
var block = getBlock(elem);
block.style.display = newVal;
elem.style.display = "none";
if (block.tagName == "DT") {
var next = getNext(block);
if (next && next.tagName == "DD")
next.style.display = newVal;
}
else if (block.tagName == "DIV") {
block.className = "filtered2";
}
else if (block.tagName.match(/^H[1-6]$/)) {
if (topicHeading(block)) {
if (newVal != "none") {
var tag = null;
if (block.children && block.children.length) {
tag = block.children[block.children.length - 1];
if (tag.className == "ilang") {
tag.innerHTML = (newVal == "block") ?
' [Language: ' + curLang + ']' : "";
}
}
}
}
else {
var next = getNext(block);
while (next && !next.tagName.match(/^(H[1-6])|(DIV)$/)) {
next.style.display = newVal;
next = getNext(next);
}
}
}